var utils = require("../../../utils/util.js");
var app = getApp();
Page({
  data: {
    arr:[],
    dominameImg:utils.dominameImg,
    pageIndex:1,
    pageSize:4,
    hasData:true,
  },
  onLoad: function (options){
    this.setData({
      parent_id:options.id
    });
    this.ajax();
  },
  ajax:function(){
    let that = this;
    //wx.showLoading();
    wx.request({
      url: utils.dominame + '/api/zbds/goods/goodsList',
      data: {
        parent_id: that.data.parent_id,
        pageIndex:that.data.pageIndex,
        pageSize:that.data.pageSize
      },
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      complete: function (res) {
       //wx.hideLoading();
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          var arrBox;
          if (that.data.pageIndex == 1) {
            arrBox = res.data.data.rows;
          } else {
            arrBox = that.data.arr.concat(res.data.data.rows)
          };
          if (that.data.pageSize * that.data.pageIndex < res.data.data.recordCount) {
            var num = that.data.pageIndex + 1;
            that.setData({
              arr: arrBox,
              hasData: true,
              pageIndex: num
            });
          } else {
            that.setData({
              arr: arrBox,
              hasData: false
            });
          }
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }
      }
    })
  },
  goProductDetail:function(e){
    wx.navigateTo({
      url: '../shopMallProductDetail/productDetail?id=' + e.currentTarget.id,
    });
  },
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {
    this.setData({
      pageIndex:1,
      hasData:true
    });
    this.ajax();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.hasData) {
      this.ajax();
    }
  },
})